import aixos from "axios";

const instance = aixos.create({
    baseURL: "http://kumanxuan1.f3322.net:8881/cms"
})


// 请求拦截器
instance.interceptors.request.use(config => {
    // 统一携带请求头token
    let token = localStorage.getItem('x-auth-token')
    if (token) {
        config.headers['x-auth-token'] = token
    }

    console.log("请求拦截器！");
    return config
}, error => {
    return Promise.reject(error)
})


// 响应拦截器
instance.interceptors.response.use(response => {
    if (response.data.code != 0 && response.data.code != 407 && response.data.code != 400) {
        alert(response.data.message);
        return;
    }

    return response.data
}, error => {
    return Promise.reject(error)
})


export default instance